package adaptdesignmode;

public class BookIShelfMIterator implements MIterator <Book> {
    private BookShelf bookShelf;
    private int index;
    public  BookIShelfMIterator(BookShelf bookShelf){
        this.bookShelf=bookShelf;
        this.index=0;//不需要传入初始值0
    }
    //重写hasNext  next方法
    @Override
    public boolean hasNext(){
        if(index< bookShelf.getLenngth()){
            return true;
        }else{
            return false;
        }
    }
    @Override
    public Book next(){
        Book book=bookShelf.getBookAt(index);
        index++;
        return book;
    }
}
